<?php
include_once 'BaseS.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/application/model/MemberM.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/application/model/MemberTokenM.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/util/Util.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/util/Regex.php';

class AppSettingS extends BaseS {
	
	public function __construct() {
		parent::__construct ();
		parent::setTarget ( $this );
	}
	
	public function settingPush(){
		
		$result = array("status" => 0, "msg" => "");
		
		$phoneType 		= $_POST['phoneType'];
		$phoneVersion 	= $_POST['phoneVersion'];
		$memberId 		= isset($_POST['mId']) ? $_POST['mId'] : 0 ;
		$deviceKey 		= isset($_POST['token']) ? $_POST['token'] : "" ; 
		$isPush 		= isset($_POST['isPush']) ? $_POST['isPush'] : 0 ;
		
		$dao = new memberM();
		$checkToken = new MemberTokenM();
		
		if(!Regex::isNumber($phoneType, 1))		{$result["status"] = -3; Util::toEchoJson($result); exit;}
		if(!Regex::isFloat($phoneVersion, 30))	{$result["status"] = -3; Util::toEchoJson($result); exit;}
		
		if($phoneType == 1 && $phoneVersion <= ANDROID_1 ){
			
			if(!$checkToken->checkToken($memberId, $deviceKey)) {$result["status"] = -4; Util::toEchoJson($result); exit;}
			
			$obj = array(
					"id" => $memberId,
					"push_status" => $isPush
			);
			
			$ret = $dao->update($obj);
			
			if($ret >0){
				$result['status'] = 1;
				$result['catId'] = $ret;
			}else{
				$result['status'] = -3;
			}
			
			Util::toEchoJson($result);
			exit;
			
		}else{
			Util::toEchoJson($result);
			exit;
		}
	}
	
}

if (isset($_POST["action"])) {
	$service = new AppSettingS ();
	$service->__call ( $_POST["action"], null );
} 
?>